import { Button } from "cc";


/**
 * 收集视图数据（视图名，）
 */
export function view(options:{viewName:string,params?:{[key:string]:any}}){
    return function (target: any, key: string) {
        target['views'] = target['views'] ||{};

        var v = target['views'];
    }
}



export enum UICompType{
    Path,//定位的节点
    TypeInChild,//定位节点的子节点
    TypeInDescendant//定位节点的所有后代节点
}


//#region 绑定组件或node节点
/**
 * 根据路径自动绑定组件
 *
 * @param componentPath 组件路径
 */
export function uibind(componentPath: string,classConstructure: new (...args: any[]) => any,type:UICompType=UICompType.Path) {
    return function (target: any, key: string) {
        target['controls'] = target['controls'] ||{};

        var v = target['controls'] as {[key: string]:{ componentPath: string ,classConstructure: new (...args: any[]) => any,type:UICompType}};
        v[key] = {
            classConstructure,
            componentPath,
            type
        }
    }
}
/**
 * 给指定组件绑定事件
 * @param componentPath 
 * @param classConstructure 
 * @param type 
 * @returns 
 */
export function uievent(componentPath: string,classConstructure: new (...args: any[]) => any,eventName:string,type:UICompType=UICompType.Path,customDataFunc:string="") {
    return function (target: any, key: string) {
        target['controls'] = target['controls'] ||{};

        var v = target['controls'] as {
            [key: string]:{ 
                componentPath: string ,
                classConstructure: new (...args: any[]) => any,
                eventName:string,
                type:UICompType,
                customDataFunc:string
            }
        };
        v[key] = {
            classConstructure,
            componentPath,
            eventName,
            type,
            customDataFunc
        }
    }
}

/**
 * 绑定事件时自定义数据来源
 * @returns 
 */
export function uicustomdata() {
    return function (target: any, key: string) {
        target['controls'] = target['controls'] ||{};

        var v = target['controls'] as {[key: string]:{ componentPath: string ,classConstructure: new (...args: any[]) => any}};

    }
}
